<?php

namespace app\common\logic;

use think\Model;

class AuthGroupAccess extends Model
{
    protected function getLastLoginTimeAttr($value)
    {
        return recent_time($value);
    }

    public static function getAdminList($where = [], $order = 'r.create_time desc')
    {
        $where['l.group_id'] = c('admin_group_id');
        $rows = empty(input('rows')) ? config('paginate.list_rows') : input('rows');
        $list = self::where($where)->alias('l')->join('sys_user r', 'l.user_id = r.id', 'left')
            ->field('l.*,r.id,r.username,r.email,r.last_login_time,r.last_login_ip')->order($order)->paginate($rows);
        $ret = $list->render();
        return $ret;
    }

    public static function getCentreAdminList($where = [], $order = 'r.create_time desc')
    {
        $where['l.group_id'] = c('centre_admin_group_id');
        $rows = empty(input('rows')) ? config('paginate.list_rows') : input('rows');
        $list = self::where($where)->alias('l')->join('sys_user r', 'l.user_id = r.id', 'left')
            ->join('sys_centre t', "l.centre_id = t.id", 'left')
            ->field('l.*,r.id,r.username,r.email,r.last_login_time,r.last_login_ip,t.name')->order($order)->paginate($rows);
        $ret = $list->render();
        return $ret;
    }
}